import { TOOL_CLASS_IDENTIFIER, TOOL_PROVIDER_CLASS_IDENTIFIER } from "@/services/constants";
import { dsFind } from "../datasource";
import { Tool, ToolType } from "./tool";
import { ComparsionOperator } from "../types";
import { fetchAllBuiltInTools11 } from "@/services/tools";


export interface ToolProvider {
    id: number;
    identifier: string;
    name: string;
    title: string;
    icon?: string;
    type?: ToolType;
    description?: string;
    tools?: Array<Tool>;
    labels?: string[]
}


export const toolFetchProviderToolsByType = async (toolType: ToolType): Promise<Array<ToolProvider>> => {
    try {
        let response = await dsFind(0, TOOL_PROVIDER_CLASS_IDENTIFIER,
            {
            },
            {
                class_selector: {
                    "tools": [
                        TOOL_CLASS_IDENTIFIER,
                        {
                            attributes: [{
                                name: 'tool_type',
                                operator: ComparsionOperator.Equal,
                                value: toolType
                            }],
                            relations: [
                                {
                                    conditions: {
                                        related_at: 'provider_identifier'
                                    }
                                }
                            ]
                        }
                        , { class_selector: {} }
                    ],
                },
            }
        );

        const { data, total } = response;

        return data.map((item, index) => {
            return {
                ...item,
            };
        });
    } catch (err) {
        console.error(err);
    }
    //
    return []
}
